#ifndef __STEPMOTOR_H
#define __STEPMOTOR_H

#include "point.h"


typedef struct {
    GPIO_TypeDef* DIR_Port;
    uint16_t DIR_Pin;
    GPIO_TypeDef* PUL_Port;
    uint16_t PUL_Pin;
    volatile int Pulse;
	volatile int Speed;
} StepMotor;

typedef enum {
    IDLE,
    READY,
	UP,
	DOWN,
	GOPIECE,
	GOBOARD,
	OK
} MotorState;

extern StepMotor motorX;
extern StepMotor motorY;
extern StepMotor motorZ;

extern MotorState motorZ_state;
extern MotorState motorXY_state;

void StepMotor_Init(StepMotor* motor, GPIO_TypeDef* DIR_Port, uint16_t DIR_Pin,
			   						  GPIO_TypeDef* PUL_Port, uint16_t PUL_Pin);

void StepMotor_Stop(StepMotor* motor);

void StepMotor_Speed(StepMotor* motor);

void StepMotor_Pluse(StepMotor* motor);

void GoToPoint(Point *current, Point *target);

int OnThePoint(Point *current, Point *target);

void GetPiece(void);

void PutPiece(void);

void PlacePiece(Point *motor, Point *piece, Point *target);

void SetOrigin(Point *motor, Point *origin);

#endif
